package ua.edu.nuos.jeetraining2012.cms.ui.components;

import com.vaadin.navigator.Navigator;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.MenuBar;
import ua.edu.nuos.jeetraining2012.cms.ui.events.AdminMenuBarCommand;
import ua.edu.nuos.jeetraining2012.cms.ui.events.LanguageMenuBarCommand;
import ua.edu.nuos.jeetraining2012.cms.util.LocaleWrapper;

import java.util.ResourceBundle;

/**
 * Class creates header of admin page
 */
public class HeaderPanel {

    private HorizontalLayout headerLayout;
    private MenuBar menuBar;
    private MenuBar languageBar;

    private Navigator navigator;

    private ResourceBundle bundle;
    private String viewName;


    public HeaderPanel(Navigator navigator, String viewName) {

        bundle = LocaleWrapper.getBundle("admin");
        this.viewName = viewName;

        this.navigator = navigator;

        makeLanguageBar();
        makeMenuBar();

        headerLayout = new HorizontalLayout();
        headerLayout.setWidth("100%");
        headerLayout.addComponent(menuBar);
        headerLayout.addComponent(languageBar);

        headerLayout.setExpandRatio(menuBar, 0.95f);
        headerLayout.setExpandRatio(languageBar, 0.05f);


    }

    //get layout component with menu bar for adding on layout in specified view
    public HorizontalLayout getHeaderLayout() {
        return headerLayout;
    }


    private void makeMenuBar() {
        menuBar = new MenuBar();
        menuBar.addItem(bundle.getString("courses"),
                new AdminMenuBarCommand("", navigator).menuSelected());

        menuBar.setSizeFull();
    }

    private void makeLanguageBar() {

        languageBar = new MenuBar();
        MenuBar.MenuItem language = languageBar.addItem(bundle.getString("language"), null);

        language.addItem("ua", new LanguageMenuBarCommand("ua", "UA").menuSelected());
        language.addItem("ru", new LanguageMenuBarCommand("ru", "RU").menuSelected());

        languageBar.setSizeFull();

    }

    public String getViewName() {
        return viewName;
    }


}
